﻿using System;
using System.Windows.Forms;

namespace LD
{
    public partial class FrmReBali : Form
    {
        private TB_Product m_product;
        public FrmReBali()
        {
            InitializeComponent();
            this.ControlBox = false;
        }

        public FrmReBali(TB_Product product) : this()
        {
            m_product = product;
            lab_msg.Text = m_product?.Barcode + "_Insight上传失败";
        }
        private const int CP_NOCLOSE_BUTTON = 0x200;

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        }

        private void btn_Exit_Click(object sender, EventArgs e)
        {
            if (m_product != null)
            {
                foreach (var item in m_product.ScrewDatas)
                {
                    MesHelper.Instance.UploadImg(m_product.Barcode,item.FileName+".jpg", item.FilePath + ".jpg");
                }

                //上传MES
                var result = MesHelper.Instance.Post(m_product, "续传");
                if (!result)
                {
                    MessageBox.Show("上传失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            this.Close();
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x112)
            {
                switch ((int)m.WParam)
                {
                    //禁止双击标题栏关闭窗体
                    case 0xF063:
                    case 0xF093:
                        m.WParam = IntPtr.Zero;
                        break;

                    //禁止双击标题栏
                    case 0xf022:
                        m.WParam = IntPtr.Zero;
                        break;
                }
            }
            base.WndProc(ref m);
        }
    }
}
